home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Utilities / EditrSet.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  3.0 KB  |  160 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        EditrSet.cpp
  3.  
  4.     Contains:    C++ Implementation for EditorSet and EditorSetIterator.
  5.  
  6.     Owned by:    Eric House
  7.  
  8.     Copyright:    © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     
  11. */
  12.  
  13.  
  14. #ifndef _EDITRSET_
  15. #include "EditrSet.h"
  16. #endif
  17.  
  18. #ifndef _ORDCOLL_
  19. #include "OrdColl.h"
  20. #endif
  21.  
  22. #ifndef _ODUTILS_
  23. #include <ODUtils.h>
  24. #endif
  25.  
  26. #ifndef _ISOSTR_
  27. #include "ISOStr.h"
  28. #endif
  29.  
  30.  
  31. //==============================================================================
  32. // Class EditorSet
  33. //==============================================================================
  34.  
  35. EditorSet::EditorSet()
  36. {
  37.     fSet = kODNULL;
  38.     fEv = kODNULL;
  39. }
  40.  
  41. void EditorSet::InitEditorSet()
  42. {
  43.     fEv = somGetGlobalEnvironment ();
  44.     fSet = new OrderedCollection();
  45. }
  46.  
  47. EditorSet::~EditorSet()
  48. {
  49.     fSet->DeleteAll();
  50.     delete fSet;
  51. }
  52.     
  53. void EditorSet::AddEditor(ODEditor editor)
  54. {
  55.     if ( !this->ContainsEditor(editor) )
  56.     {
  57.         ODULong strLength = ODISOStrLength((const ODISOStr)editor);
  58.         ElementType newEditor = ODNewPtrClear(strLength+1,0);
  59.         ODISOStrNCopy((const ODISOStr)newEditor, (ODISOStr)editor, strLength );
  60.         fSet->AddLast(newEditor);
  61.     }
  62. }
  63.  
  64. void EditorSet::AddEditorSet( EditorSet* editors )
  65. {
  66.     EditorSetIterator* esi = editors->CreateIterator() ;
  67.     for ( ODEditor editor = esi->First() ; esi->IsNotComplete() ;
  68.             editor = esi->Next() )
  69.     {
  70.         this->AddEditor( editor ) ;
  71.     }
  72.     ODDeleteObject( esi );
  73. }
  74.  
  75. void EditorSet::RemoveEditor(ODEditor editor)
  76. {
  77.     if (fSet->Contains((ElementType)editor) != kODFalse)
  78.         fSet->Remove((ElementType)editor);
  79. }
  80.     
  81. void EditorSet::RemoveEditor(EditorSet* editors )
  82. {
  83.     EditorSetIterator* esi = editors->CreateIterator() ;
  84.     for ( ODEditor editor = esi->First() ; esi->IsNotComplete() ;
  85.             editor = esi->Next() )
  86.     {
  87.         this->RemoveEditor(editor);
  88.     }
  89.     ODDeleteObject( esi );
  90. }
  91.  
  92. void EditorSet::RemoveAllEditors()
  93. {
  94.     if ( fSet->Count() > 0 )
  95.     {
  96.         fSet->DeleteAll();
  97.     }
  98. }
  99.  
  100. ODBoolean EditorSet::ContainsEditor(ODEditor editor)
  101. {
  102.     ODBoolean rslt = kODFalse;
  103.     
  104.     if ( this->GetEditorCount() )
  105.     {
  106.         EditorSetIterator* editorIter = this->CreateIterator();
  107.         
  108.         for (ODEditor anEditor = editorIter->First();
  109.             editorIter->IsNotComplete() && (rslt == kODFalse);
  110.             anEditor = editorIter->Next())
  111.         {
  112.             rslt = (anEditor == editor) || ODISOStrEqual(anEditor, editor);
  113.         }
  114.  
  115.         delete editorIter;
  116.     }
  117.     
  118.     return rslt;
  119. }
  120.  
  121. ODULong EditorSet::GetEditorCount()
  122. {
  123.     return (fSet->Count());
  124. }
  125.  
  126. EditorSetIterator* EditorSet::CreateIterator()
  127. {
  128.     //return new EditorSetIterator(this);
  129.     return new EditorSetIterator(this);
  130. }
  131.  
  132. //==============================================================================
  133. // Class EditorSetIterator
  134. //==============================================================================
  135.  
  136. EditorSetIterator::EditorSetIterator(EditorSet* set)
  137. {
  138.     fIterator = new OrderedCollectionIterator(set->fSet);
  139. }
  140.  
  141. EditorSetIterator::~EditorSetIterator()
  142. {
  143.     delete fIterator;
  144. }
  145.     
  146. ODEditor EditorSetIterator::First()
  147. {
  148.     return (ODEditor)fIterator->First();
  149. }
  150.  
  151. ODEditor EditorSetIterator::Next()
  152. {
  153.     return (ODEditor)fIterator->Next();
  154. }
  155.  
  156. ODBoolean EditorSetIterator::IsNotComplete()
  157. {
  158.     return fIterator->IsNotComplete();
  159. }
  160.